home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Saar AMOK 2
/
Saar AMOK II - Oktober 1994 (1994)(Kreativ Marketing)(DE)[!][I-7598].iso
/
tools
/
toolalias
/
source.lha
/
list.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-21
|
3KB
|
165 lines
/*
* List operations for ToolAlias.
*
* mws, 4 February 1993
*/
#include <exec/memory.h>
#include <proto/exec.h>
#include <string.h>
#include "list.h"
static TOOL *head; /* empty */
void
free_tool(TOOL *tool)
{
if (tool->oldname) FreeVec(tool->oldname);
if (tool->newname) FreeVec(tool->newname);
FreeVec(tool);
}
/* get head of list */
TOOL *
get_head()
{
return head;
}
/* get tail of list */
TOOL *
get_tail()
{
TOOL *tool = head;
while (tool && tool->next)
tool = tool->next;
return tool;
}
/* add a new entry after given position in list, returning new entry/NULL if failure */
TOOL *
add_tool(TOOL *curtool)
{
TOOL *newtool;
Forbid();
if (newtool = AllocVec(sizeof(TOOL), MEMF_CLEAR|MEMF_PUBLIC))
{
if (curtool) /* list non-empty */
{
newtool->prev = curtool;
newtool->next = curtool->next;
if (curtool->next)
curtool->next->prev = newtool;
curtool->next = newtool;
}
else /* empty list - initialize */
{
head = newtool;
}
}
Permit();
return newtool;
}
/* remove current entry, return prev if exists, else next */
TOOL *
rem_tool(TOOL *tool)
{
TOOL *curtool;
Forbid();
if (tool->prev)
tool->prev->next = tool->next;
else
/* first tool in list - change head */
head = tool->next;
if (tool->next)
tool->next->prev = tool->prev;
/* determine current tool after deletion */
curtool = tool->prev ? tool->prev : tool->next;
free_tool(tool);
Permit();
return curtool;
}
/* set/update oldname in tool entry - returns success/failure */
BOOL
set_oldname(TOOL *tool, char *oldname)
{
char *name;
if (name = AllocVec(strlen(oldname)+1, MEMF_PUBLIC|MEMF_CLEAR))
{
Forbid();
if (tool->oldname)
FreeVec(tool->oldname);
strcpy(name, oldname);
tool->oldname = name;
Permit();
return TRUE;
}
return FALSE;
}
/* set/update newname in tool entry - returns success/failure */
BOOL
set_newname(TOOL *tool, char *newname)
{
char *name;
if (name = AllocVec(strlen(newname)+1, MEMF_PUBLIC|MEMF_CLEAR))
{
Forbid();
if (tool->newname)
FreeVec(tool->newname);
strcpy(name, newname);
tool->newname = name;
Permit();
return TRUE;
}
return FALSE;
}
/* look-up oldname in list, return newname or NULL if not found */
char *
find_tool(char *name)
{
TOOL *tool;
Forbid();
tool = head;
while (tool)
{
if (tool->oldname && *tool->oldname) /* non-null */
if (!stricmp(name, tool->oldname)) /* case-insensitive */
{
Permit();
return tool->newname;
}
tool = tool->next;
}
Permit();
return NULL;
}
/* remove whole list from memory */
void
free_list()
{
TOOL *tool, *next;
Forbid();
tool = head;
while (tool)
{
next = tool->next;
free_tool(tool);
tool = next;
}
head = NULL;
Permit();
}